package com.example.chenkezhen

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import java.io.File

class HistoryActivity : AppCompatActivity() {

    private lateinit var recyclerView: RecyclerView
    private lateinit var adapter: PrimeAdapter



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_history)

        recyclerView = findViewById(R.id.recycler_view)
        recyclerView.layoutManager = LinearLayoutManager(this)

        val primes = readPrimesFromFile()
        adapter = PrimeAdapter(primes)
        recyclerView.adapter = adapter
    }

    private fun readPrimesFromFile(): List<String> {
        val file = File(filesDir, "primes_data.txt")
        if (file.exists()) {
            val primes = file.readLines()
            Log.d("HistoryActivity", "Primes loaded: $primes") // 打印读取的数据
            return primes
        } else {
            Log.d("HistoryActivity", "File does not exist")
            return emptyList()
        }
    }

}